package god;

public class J16Ch05Printer {

	public static void main(String[] args) {
		J16Printer p = new J16Printer("S", "S301", "USB 2.0");
		System.out.println(p.toString());
		
		J16InkjetPrinter ip = new J16InkjetPrinter("A", "A301", "USB 3.0");
		System.out.println(ip.toString());
		
		J16LazerPrinter lp = new J16LazerPrinter("C", "C301", "USB 3.0");
		System.out.println(lp.toString());
		
		J16PrinterService ps = new J16PrinterService();
		ps.print(p);
		ps.print(ip);
		ps.print(lp);
	}
}

class J16Printer {
	private String maker;
	private String model;
	private String interfaces;
	private int counts;
	private int remains;
	
	public J16Printer(String maker, String model, String interfaces) {
		this.maker = maker;
		this.model = model;
		this.interfaces = interfaces;
	}

	public String getMaker() { return maker; }
	public void setMaker(String maker) { this.maker = maker; }

	public String getModel() { return model; }
	public void setModel(String model) { this.model = model; }

	public String getInterfaces() { return interfaces; }
	public void setInterfaces(String interfaces) { this.interfaces = interfaces; }

	public int getCounts() { return counts; }
	public void setCounts(int counts) { this.counts = counts; }

	public int getRemains() { return remains; }
	public void setRemains(int remains) { this.remains = remains; }
	
	@Override
	public String toString() {
		String result = "";
		result += maker + "/" + model + "/" + interfaces + "/" + counts + "/" + remains;
		return result;
	}
}

class J16InkjetPrinter extends J16Printer {

	public J16InkjetPrinter(String maker, String model, String interfaces) {
		super(maker, model, interfaces);		// 부모 클래스의 생성자를 가리키는 말. 부모 클래스의 생성자를 호출해서 값을 저장. this 3줄을 super 하나로 대체
	}
}

class J16LazerPrinter extends J16Printer {
	
	public J16LazerPrinter(String maker,String model, String interfaces) {
		super(maker, model, interfaces);
	}
}

interface J16PrinterIService {
	void print(J16Printer p);
}

class J16PrinterService implements J16PrinterIService {

	@Override
	public void print(J16Printer p) {											// 업캐스팅. p, ip, lp 도 선언 해야 하지만 ip, lp는 p의 모든걸 상속 받고 있기 때문에
		String result = p.getModel() + "가 출력합니다.";				// 잠시 p로 둔갑시켜서 활용할 수 있다. 그래서 p만 받아서 출력하지만 ip, lp 도 출력이 된다.
		System.out.println(result);
	}
}